
#include "odn_scene_PhysicsModel.h"
#include "Vector3D.h"
#include "RGBAColor.h"

#include <vector>

class ODN_Particle : ouden::scene::ODN_PointObject
{
	
public:
	
	ODN_Particle()		{}
	~ODN_Particle()		{}
	
	virtual bool Update()
	{
		
		ODN_PhysicsModel::Update();
		
		//force += g * mass * (Dw/properties.density - 1)	;
		
	};
	
	//TODO: Access functions 
	
	struct sProperties {
		float size;			//Current radius of the particle 
		RGBAColor color;	//Current color of the particle 
		float density;		//Current density of the object 
	} properties;
	
private:
	
	bool isalive;		//Is the particle still alive? 
	long birthtime;		//The time when then particle was created 
	long lifetime;		//How long the particle lives for 
	
	
};

class ODN_Emitter : public ouden::scene::ODN_PointObject 
{
	
public:
	
	virtual bool Update()
	{
		
		for (int i=0;i<particles.size();i++) {
			
			
			
			//When particle dies, reset its properties to their defaults 
			
		}
		
	}
	
	virtual bool Draw();
	
	void setParticleCount(int n)				{ particles.resize(n); }
	
protected:
	
	//Pure virtual function to calculate the properties of a particle depending on its age 
	virtual ODN_Particle::sProperties calcProperties(float AgeFraction) = 0;
	
	//Array of all the particles of the emitter 
	std::vector<ODN_Particle*> particles;
	
};

class ODN_SimpleEmitter : public ODN_Emitter
{
	
public:
	
	
	
protected:	
	
	//Overloaded function to calculate the properties of the particles depending on their age 
	virtual ODN_Particle::sProperties calcProperties(float AgeFraction)
	{
		
		//Here, particle properties are interpolated between a sequence of values 
		
		ODN_Particle::sProperties properties;
		
		//Do blending of properties 
		//**************************
		
		float Fraction, f;
		int FractionInt;
		
		//Blend the colours
		Fraction = AgeFraction * (colorsequence.size() - 1);
		FractionInt = int(Fraction);
		f = Fraction - FractionInt;	//f is the fraction between the current colour and the next colour
		properties.color = (1-f) * colorsequence[FractionInt] + f * colorsequence[FractionInt + 1];
		
		//Blend the sizes 
		Fraction = AgeFraction * (sizesequence.size() - 1);
		FractionInt = int(Fraction);
		f = Fraction - FractionInt;	//f is the fraction between the current size and the next size
		properties.size = (1-f) * sizesequence[FractionInt] + f * sizesequence[FractionInt + 1];
		
		//Blend the densities  
		Fraction = AgeFraction * (densitysequence.size() - 1);
		FractionInt = int(Fraction);
		f = Fraction - FractionInt;	//f is the fraction between the current density and the next density
		properties.density = (1-f) * densitysequence[FractionInt] + f * densitysequence[FractionInt + 1];
		
		//**************************
		
		return properties;
		
	}
	
private:
	
	//Sequences of particle properties through which the particles change over their lifetime 
	std::vector<RGBAColor>	colorsequence;
	std::vector<float>		sizesequence;
	std::vector<float>		densitysequence;
	
};

//TODO: See if need this or can use scene instead 
class ODN_ParticleManager
{
	
	
	
};
